package com.ferry.transport.netty.server;

import com.ferry.transport.netty.provider.ServiceWrapper;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import java.util.List;
import java.util.concurrent.ConcurrentMap;

public class DefaultServiceProviderContainer {

        private final ConcurrentMap<String, ServiceWrapper> serviceProviders = Maps.newConcurrentMap();

        public void registerService(String uniqueKey, ServiceWrapper serviceWrapper) {
            serviceProviders.put(uniqueKey, serviceWrapper);
        }

        public ServiceWrapper lookupService(String uniqueKey) {
            return serviceProviders.get(uniqueKey);
        }

        public ServiceWrapper removeService(String uniqueKey) {
            ServiceWrapper serviceWrapper = serviceProviders.remove(uniqueKey);
            return serviceWrapper;
        }

        public List<ServiceWrapper> getAllServices() {
            return Lists.newArrayList(serviceProviders.values());
        }
    }